<?php
function getLink() {
  $link = mysqli_connect("localhost","MYSQLUSERFORUSERSDB","MYSQLUSERFORUSERSDB","usersdb");
  if(mysqli_connect_errno()) {
    echo "Error de enlace de conexión a MySQL: " . mysqli_connect_error();
    exit();
  }
  return $link;
}

function executeQuery($query) {
  $op = substr($query, 0, 3);
  $link = getLink();
  $result = mysqli_query($link, $query);
  switch ($op) {
    case 'SEL':
      $return = ($result)? $result:false;
      break;
    default:
      $return = mysqli_affected_rows($link);
      break;
  }
  mysqli_close($link);  
  return $return;
}

function hashPass($pass) {
  return sha1(md5($pass));
}

function goToURL($url, $msg=false) {
	if($msg) {
		$url = "$url?msg=$msg";
	}
  header("Location: $url");
  exit();	
}

function sessionCheck() {
  session_start();
  if( !isset($_SESSION['e22456391ee147ba0c4426e1f77f8936cc24b452']) )  {
  	goToURL('index.php','Acceso restringido a usuarios autenticados');
  }
}


?>